package pos.domain;

import java.util.List;

import pos.data.JDBCCategoryDAO;

public class CategoryStore {

	@SuppressWarnings("unused")
	private List<Category> categories;
	private static CategoryStore categoryStore;
	
	public static synchronized CategoryStore getInstance() {
		categoryStore = new CategoryStore();
		
		return categoryStore;
	}
	public CategoryStore() {
		categories = (new JDBCCategoryDAO()).getAllCategories();
	}
	
	public List<Category> getCategories(){
		//return categories;
		return (new JDBCCategoryDAO()).getAllCategories();
	}
	
	public Category getCategoryById(String idCategory){
		return (new JDBCCategoryDAO()).getCategoryById(idCategory);
	}
	
	public Category getCategoryByName(String name){
		return (new JDBCCategoryDAO()).getCategoryByName(name);
	}
	
	public Category insertCategory(Category category){
		Category cRes = null;
		cRes = new JDBCCategoryDAO().insertCategory(category);

		return cRes;
	}
	
	public void removeCategory(Category category){
		// didn't remove the associations because the objective is to have data
		new JDBCCategoryDAO().removeCategory(category); 
	}
	
	public boolean existCategory(Category category){
		return new JDBCCategoryDAO().existCategory(category.getName());
	}
}
